package com.wctj.api.base.async;

import com.wctj.api.base.dto.JwtUserDTO;
import org.jetbrains.annotations.NotNull;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 带有用户信息的线程池
 * @author qy
 * @since 2023/4/11 14:55
 */
public class UserContextTaskExecutor extends ThreadPoolTaskExecutor {

    private static final long serialVersionUID = 7334165009514720624L;

    private JwtUserDTO currentUser;

    public void user(JwtUserDTO currentUser) {
        this.currentUser = currentUser;
    }

    public void execute(JwtUserDTO currentUser, @NotNull Runnable task, UserContextRunnable task1) {
        super.execute(task1);
    }

    public void execute(@NotNull Runnable task) {
        if (currentUser != null) {
            super.execute(new UserContextRunnable(currentUser, task));
        }else{
            super.execute(task);
        }
    }


}